<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="java,jni,swig,android," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="说在前面JNI这个话题原来比较老旧，是10年左右的事情，这次翻出来整理是因为又碰到了需求。现在网上介绍Swig的已经比较多了，有实际例子的比较少，这里梳理的同时，做一个实际的例子。
JNI技术是在Java最初版本进行开发时就有了，主要实现Java语言与其他语言如C/C++/Delphi等的交互。最初用到它是开发物联网的项目，产品需要与各种物联网终端进行适配对接，物联网终端的各个生产厂家提供的接口五">
<meta property="og:type" content="article">
<meta property="og:title" content="使用Swig封装DLL实现JNI快速开发">
<meta property="og:url" content="http://chrisrc.me/2015/06/07/java-jni-with_swig/index.html">
<meta property="og:site_name" content="山中，山外与俯瞰">
<meta property="og:description" content="说在前面JNI这个话题原来比较老旧，是10年左右的事情，这次翻出来整理是因为又碰到了需求。现在网上介绍Swig的已经比较多了，有实际例子的比较少，这里梳理的同时，做一个实际的例子。
JNI技术是在Java最初版本进行开发时就有了，主要实现Java语言与其他语言如C/C++/Delphi等的交互。最初用到它是开发物联网的项目，产品需要与各种物联网终端进行适配对接，物联网终端的各个生产厂家提供的接口五">
<meta property="og:updated_time" content="2016-12-17T04:01:46.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用Swig封装DLL实现JNI快速开发">
<meta name="twitter:description" content="说在前面JNI这个话题原来比较老旧，是10年左右的事情，这次翻出来整理是因为又碰到了需求。现在网上介绍Swig的已经比较多了，有实际例子的比较少，这里梳理的同时，做一个实际的例子。
JNI技术是在Java最初版本进行开发时就有了，主要实现Java语言与其他语言如C/C++/Delphi等的交互。最初用到它是开发物联网的项目，产品需要与各种物联网终端进行适配对接，物联网终端的各个生产厂家提供的接口五">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://chrisrc.me/2015/06/07/java-jni-with_swig/"/>





  <title> 使用Swig封装DLL实现JNI快速开发 | 山中，山外与俯瞰 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">山中，山外与俯瞰</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">一次永不停止的探索之旅</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-dcos">
          <a href="/dcos" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            DC/OS
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="st-search-show-outputs">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <form class="site-search-form">
  <input type="text" id="st-search-input" class="st-search-input st-default-search-input" />
</form>

<script type="text/javascript">
  (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
    (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
    e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
  })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');

  _st('install', 'R9GcmhBwxpsAGLNCsquZ','2.0.0');
</script>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://chrisrc.me/2015/06/07/java-jni-with_swig/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="chrisrc">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.gif">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="山中，山外与俯瞰">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="山中，山外与俯瞰" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                使用Swig封装DLL实现JNI快速开发
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2015-06-07T20:16:24+08:00">
                2015-06-07
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Snippets/" itemprop="url" rel="index">
                    <span itemprop="name">Snippets</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <a href="/2015/06/07/java-jni-with_swig/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/06/07/java-jni-with_swig/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="说在前面"><a href="#说在前面" class="headerlink" title="说在前面"></a>说在前面</h2><p>JNI这个话题原来比较老旧，是10年左右的事情，这次翻出来整理是因为又碰到了需求。现在网上介绍Swig的已经比较多了，有实际例子的比较少，<br>这里梳理的同时，做一个实际的例子。</p>
<p>JNI技术是在Java最初版本进行开发时就有了，主要实现Java语言与其他语言如C/C++/Delphi等的交互。<br>最初用到它是开发物联网的项目，产品需要与各种物联网终端进行适配对接，物联网终端的各个生产厂家提供的接口五花八门，<br>C，C++，Delphi的，接口封装的形式也是各不相同，为每一种设备做适配封装成为一个巨大的挑战。</p>
<p>在使用JNI封装了一个设备之后，脑力消耗巨大，因为用JNI封装一个简单的函数和封装几十上百个函数不是同一个等级的。为了快速解决问题，<br>只能在网上一遍遍搜索，最后发现了<a href="http://www.swig.org/" target="_blank" rel="external">Swig</a></p>
<h2 id="Swig简介"><a href="#Swig简介" class="headerlink" title="Swig简介"></a>Swig简介</h2><p>Swig的目标是为C/C++开发的程序与其他语言开发的程序之间建立连接。Swig支持的语言包括：Javascript, Perl, PHP, Python, Tcl and Ruby，<br>C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), D, Go language, Java including Android, Lua, Modula-3, OCAML, Octave, Scilab and R。可以看出，几乎涵盖了大多数常用语言。</p>
<p>Swig的实现机制是通过定义中间接口描述文件，根据接口描述文件自动生成DLL的封装代码，包括C/C++封装代码和目标语言的封装代码。当前，<br>Swig支持C++的如下特性：  </p>
<ul>
<li>类</li>
<li>类的构造和析构</li>
<li>虚函数</li>
<li>公共继承（包括多重继承）</li>
<li>静态函数</li>
<li>函数和方法重载</li>
<li>大多数标准运算符的重载</li>
<li>引用</li>
<li>模板</li>
<li>函数指针</li>
<li>名字空间</li>
</ul>
<h2 id="Swig的安装"><a href="#Swig的安装" class="headerlink" title="Swig的安装"></a>Swig的安装</h2><p>Swig支持Windows，Linux和Mac。在Windows平台下，下载SwigWin-[VERSION]安装包即可；在Linux平台可以从仓库直接安装，如果想使用最新版本，<br>可以下载代码编译：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">./configure</div><div class="line">make</div><div class="line">make install</div></pre></td></tr></table></figure>
<p>最后的<code>make install</code>需要 <strong>root</strong> 权限。</p>
<h2 id="Swig在JNI中的应用"><a href="#Swig在JNI中的应用" class="headerlink" title="Swig在JNI中的应用"></a>Swig在JNI中的应用</h2><p>下面以一个实际的JNI封装案例简要介绍Swig的使用。</p>
<h3 id="待封装的DLL及头文件"><a href="#待封装的DLL及头文件" class="headerlink" title="待封装的DLL及头文件"></a>待封装的DLL及头文件</h3><p>通常拿到的SDK开发接口包括：DLL，.h头文件，.lib文件。下面的示例SDK接口包含：</p>
<ul>
<li>RR3036.dll</li>
<li>RR3036.h</li>
<li>RR3036.lib</li>
</ul>
<p>其中，头文件 <strong>RR3036.h</strong> 的部分内容摘录（仅占三分之一）如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div></pre></td><td class="code"><pre><div class="line">#ifdef RR3036_EXPORTS</div><div class="line">#define RR3036_API __declspec(dllexport)</div><div class="line">#else</div><div class="line">#define RR3036_API __declspec(dllimport)</div><div class="line">#endif</div><div class="line"></div><div class="line">// 此类是从 RR3036.dll 导出的</div><div class="line">class RR3036_API CRR3036 &#123;</div><div class="line">public:</div><div class="line">	CRR3036(void);</div><div class="line">&#125;;</div><div class="line"></div><div class="line">extern RR3036_API int nRR3036;</div><div class="line"></div><div class="line">RR3036_API int fnRR3036(void);</div><div class="line"></div><div class="line">#ifdef __cplusplus</div><div class="line">extern &quot;C&quot; &#123;</div><div class="line">#endif</div><div class="line"></div><div class="line">RR3036_API int CloseSpecComPort(int FrmHandle);</div><div class="line">RR3036_API int CloseComPort();</div><div class="line">RR3036_API int GetReaderInformation(unsigned char* ComAdr,				//读写器地址</div><div class="line">									unsigned char* VersionInfo,			//软件版本</div><div class="line">									unsigned char* ReaderType,				//读写器型号</div><div class="line">									unsigned char* TrType,		//支持的协议</div><div class="line">									unsigned char* ScanTime,</div><div class="line">									int frmComPortindex);</div><div class="line">RR3036_API int OpenComPort(int port,unsigned char *ComAdr,int* frmcomportindex);</div><div class="line">RR3036_API int AutoOpenComPort(int *port,unsigned char *ComAdr,int *frmcomportindex);</div><div class="line">RR3036_API int Inventory(unsigned char *ComAdr,</div><div class="line">						 unsigned char *state,				//询查模式</div><div class="line">						 unsigned char *AFI,</div><div class="line">						 unsigned char *pOUcharUIDList,		//标签DSFID + UID</div><div class="line">						 unsigned char *pOUcharTagNum,</div><div class="line">						 int frmcomportindex);</div><div class="line">RR3036_API int WriteInventoryScanTime(unsigned char *ComAdr,</div><div class="line">									  unsigned char *ScanTime,</div><div class="line">									  int frmComPortindex);</div><div class="line">RR3036_API int StayQuiet(unsigned char *ComAdr,</div><div class="line">						 unsigned char *UID,//要静默标签的UID</div><div class="line">						 unsigned char *ErrorCode,</div><div class="line">						 int frmcomportindex);</div><div class="line">RR3036_API int Select(unsigned char *ComAdr,</div><div class="line">					  unsigned char *UID,</div><div class="line">					  unsigned char *ErrorCode,</div><div class="line">					  int frmcomportindex);</div><div class="line">RR3036_API int ResetToReady(unsigned char *ComAdr,</div><div class="line">							unsigned char *state,</div><div class="line">							unsigned char *UID,</div><div class="line">							unsigned char *ErrorCode,</div><div class="line">							int frmcomportindex);</div><div class="line">RR3036_API int ReadSingleBlock(unsigned char *ComAdr,</div><div class="line">							   unsigned char *state,					//读模式选择</div><div class="line">							   unsigned char *UID,</div><div class="line">							   unsigned char blockNumber,			//块号</div><div class="line">							   unsigned char *BlockSecStatus,	//安全状态字</div><div class="line">							   unsigned char *Data,			//块数据</div><div class="line">							   unsigned char *ErrorCode,</div><div class="line">							   int frmcomportindex);</div><div class="line">RR3036_API int WriteSingleBlock(unsigned char *ComAdr,</div><div class="line">								unsigned char *state,				//读模式选择</div><div class="line">								unsigned char *UID,</div><div class="line">								unsigned char blockNumber,		//块号</div><div class="line">								unsigned char *Data,		//要写入的数据</div><div class="line">								unsigned char *ErrorCode,</div><div class="line">								int frmcomportindex);</div><div class="line">RR3036_API int ReadMultipleBlock(unsigned char *ComAdr,</div><div class="line">								 unsigned char *state,				//读模式选择</div><div class="line">								 unsigned char *UID,</div><div class="line">								 unsigned char BlockNum,	//起始块号</div><div class="line">								 unsigned char BlockCount,		//块数量</div><div class="line">								 unsigned char *BlockSecStatus,//安全状态字</div><div class="line">								 unsigned char *Data,		//块数据</div><div class="line">								 unsigned char *ErrorCode,</div><div class="line">								 int frmcomportindex);</div><div class="line">......</div></pre></td></tr></table></figure>
<h3 id="接口描述文件"><a href="#接口描述文件" class="headerlink" title="接口描述文件"></a>接口描述文件</h3><p>我们需要告诉Swig，我们的接口定义头文件是什么，要封装的主类（以Java为例）是什么，接口头文件是否还依赖其他头文件，<br>需要在交互过程中对哪些类型做什么样的映射封装，根据上述信息生成 <code>RR3036.i</code> 的接口描述文件，具体如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">%module RR3036</div><div class="line">%&#123;</div><div class="line">%include &lt;windows.i&gt;</div><div class="line">%include &quot;RR3036.h&quot;</div><div class="line">%&#125;</div><div class="line"></div><div class="line">%include &lt;windows.i&gt;</div><div class="line">%include &quot;RR3036.h&quot;</div><div class="line"></div><div class="line">%include cpointer.i</div><div class="line">%pointer_functions(int, intp);</div><div class="line">%pointer_functions(unsigned char, shortp);</div><div class="line"></div><div class="line">%include &quot;carrays.i&quot;</div><div class="line">%array_functions(unsigned char, shortArray);</div></pre></td></tr></table></figure>
<p>如上所示，我们要封装成的Java代码主类为 <strong>RR3036</strong>（通过<code>%module</code>描述）。定义int型/短整型指针的类型映射封装。</p>
<p>由上面可以看出，这个过程我们几乎不需要考虑接口头文件中的具体接口方法定义。关于接口描述文件定义及类型封装请<br>参考<a href="http://www.swig.org/Doc3.0/SWIGDocumentation.html" target="_blank" rel="external">Swig帮助文档</a>。</p>
<h3 id="编译生成代码"><a href="#编译生成代码" class="headerlink" title="编译生成代码"></a>编译生成代码</h3><p>接口描述文件<code>RR3036.i</code>准备好之后就可以调用Swig命令生成封装代码，具体命令如下：</p>
<p><code>swig -c++ -java -package rr3036.api -outdir src/java/rr3036/api RR3036.i</code></p>
<p>生成的代码文件（本例）主要包括：</p>
<ul>
<li><p>两个C++封装文件：</p>
<ul>
<li>JNI_RR3036API.cpp</li>
<li>RR3036_wrap.cxx   注意，此文件中的<code>%include &lt;windows.i&gt; %include &quot;RR3036.i&quot;</code>需要调整才能编译</li>
</ul>
</li>
<li><p>多个Java封装文件：</p>
<ul>
<li>CRR3036.java</li>
<li>RR3036.java  # 要调用的主类</li>
<li>RR3036JNI.java</li>
<li>SWIGTYPE_p_int.java</li>
<li>SWIGTYPE_p_unsigned_char.java</li>
</ul>
</li>
</ul>
<p>对上述代码分别进行编译。</p>
<p><strong>备注：</strong></p>
<ul>
<li>生成的C++封装代码在Linux下的编译，在Swig中有单独说明，可参考。</li>
<li>详细编译参数，请参考Swig帮助文档。</li>
</ul>
<h3 id="调用代码"><a href="#调用代码" class="headerlink" title="调用代码"></a>调用代码</h3><p>将生成的<code>JNI_RR3036API.dll</code> 与 接口<code>RR3036.DLL</code> 通过<code>System.load</code>等方法加载后调用即可。</p>
<p>本例代码可从<a href="https://github.com/christtrc/swig-jni-rr3036" target="_blank" rel="external">swig-jni-rr3036</a>下载。</p>
<h2 id="附录"><a href="#附录" class="headerlink" title="附录"></a>附录</h2><p><a href="http://blog.csdn.net/pfgmylove/article/details/7052839" target="_blank" rel="external">[Android] Jni中C++和Java的数据类型的对应关系</a></p>
<table>
<thead>
<tr>
<th style="text-align:left">Java类型</th>
<th style="text-align:left">本地类型</th>
<th style="text-align:left">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"></td>
</tr>
</tbody>
</table>
<p>boolean    |jboolean    |C/C++8位整型<br>byte    |jbyte    |C/C++带符号的8位整型<br>char    |jchar    |C/C++无符号的16位整型<br>short    |jshort    |C/C++带符号的16位整型<br>int        |jint|    |C/C++带符号的32位整型<br>long    |jlong    |C/C++带符号的64位整型e<br>float    |jfloat    |C/C++32位浮点型<br>double    |jdouble    |C/C++64位浮点型<br>Object    |jobject    |任何Java对象，或者没有对应java类型的对象<br>Class    |jclass      |Class对象<br>String    |jstring    |字符串对象<br>Object[]    |jobjectArray    |任何对象的数组<br>boolean[]    |jbooleanArray    |布尔型数组<br>byte[]    |jbyteArray    |比特型数组<br>char[]    |jcharArray    |字符型数组<br>short[]    |jshortArray    |短整型数组<br>int[]    |jintArray    |整型数组<br>long[]    |jlongArray    |长整型数组<br>float[]    |jfloatArray    |浮点型数组<br>double[]    |jdoubleArray    |双浮点型数组  </p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag"># java</a>
          
            <a href="/tags/jni/" rel="tag"># jni</a>
          
            <a href="/tags/swig/" rel="tag"># swig</a>
          
            <a href="/tags/android/" rel="tag"># android</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/05/29/java-osgi-fragment-bundle/" rel="next" title="通过OSGi Bundle进行资源隔离">
                <i class="fa fa-chevron-left"></i> 通过OSGi Bundle进行资源隔离
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/07/27/java-osgi-build-dynamic-app-with-karaf/" rel="prev" title="Apache Karaf构建动态模块化应用(1)--OSGi回顾">
                Apache Karaf构建动态模块化应用(1)--OSGi回顾 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2015/06/07/java-jni-with_swig/"
     data-title="使用Swig封装DLL实现JNI快速开发"
     data-content=""
     data-url="http://chrisrc.me/2015/06/07/java-jni-with_swig/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2015/06/07/java-jni-with_swig/"
           data-title="使用Swig封装DLL实现JNI快速开发" data-url="http://chrisrc.me/2015/06/07/java-jni-with_swig/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="chrisrc" />
          <p class="site-author-name" itemprop="name">chrisrc</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">69</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">21</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">162</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/christtrc" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/chrisrc" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
          
        </div>

        
        
          <div class="cc-license motion-element" itemprop="license">
            <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
              <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons" />
            </a>
          </div>
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#说在前面"><span class="nav-number">1.</span> <span class="nav-text">说在前面</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Swig简介"><span class="nav-number">2.</span> <span class="nav-text">Swig简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Swig的安装"><span class="nav-number">3.</span> <span class="nav-text">Swig的安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Swig在JNI中的应用"><span class="nav-number">4.</span> <span class="nav-text">Swig在JNI中的应用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#待封装的DLL及头文件"><span class="nav-number">4.1.</span> <span class="nav-text">待封装的DLL及头文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#接口描述文件"><span class="nav-number">4.2.</span> <span class="nav-text">接口描述文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#编译生成代码"><span class="nav-number">4.3.</span> <span class="nav-text">编译生成代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#调用代码"><span class="nav-number">4.4.</span> <span class="nav-text">调用代码</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#附录"><span class="nav-number">5.</span> <span class="nav-text">附录</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">
     
      <a href="mailto:chrisrc@qq.com">chrisrc</a> 
    
  </span>
  <span class="author"> &nbsp; QQ: 58122705 </span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"chrisrc"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  








  
  

  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
<script>
(function(){
   var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?ed903ab05fbc5fa64d95e4bfbf3d3a04":"https://jspassport.ssl.qhimg.com/11.0.1.js?ed903ab05fbc5fa64d95e4bfbf3d3a04";
   document.write('<script src="' + src + '" id="sozz"><\/script>');
})();
</script>

  


</body>
</html>
